#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/12/16 21:43
# @Author  : FuKai ZHANG
# @File    : file_zip.py
# @Description :将文件或者文件夹压缩成zip
import os
import zipfile
from config.setting import ensure_path_sep


def zip_directory(directory, zip_filename):
    # 创建文件夹路径
    zip_file = zipfile.ZipFile(zip_filename, 'w', zipfile.ZIP_DEFLATED)
    # 添加目录下的所有文件和文件夹
    for root, dirs, files in os.walk(directory):
        for file in files:
            file_path = os.path.join(root, file)
            zip_file.write(file_path)
    zip_file.close()
    print('Zip file created!')


if __name__ == '__main__':
    zip_directory(ensure_path_sep('\\report'), 'report.zip')
